package com.xiaoxian.basic.service.impl;

import com.xiaoxian.basic.mapper.BaseMapper;
import com.xiaoxian.basic.query.BaseQuery;
import com.xiaoxian.basic.service.IBaseService;
import com.xiaoxian.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;
    @Transactional
    @Override
    public void add(T t) {
        mapper.add(t);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }
    @Transactional
    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public T queryOne(Long id) {
        return mapper.findOne(id);
    }

    @Override
    public List<T> queryAll() {
        return mapper.findAll();
    }


    @Override
    public PageList<T> queryPage(BaseQuery query) {
        return new PageList<>(mapper.getCount(query),mapper.pageList(query));
    }
    @Transactional
    @Override
    public void patchDelete(List<Long> ids) {
        mapper.patchDelete(ids);
    }
}
